/**
 * 
 */
package mockapp;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import junit.framework.TestCase;

import org.apache.commons.beanutils.MethodUtils;

/**
 * @author Rodrigo Barbosa Lira
 *
 */
public class SampleServerAppImplTest extends TestCase {
	
	private SampleServerApp app;
	private SampleClientApp c1;
	private SampleClientApp c2;

	@Override
	protected void setUp() throws Exception {
		app = new SampleServerAppImpl();
		c1 = new SampleClientAppImpl();
		c2 = new SampleClientAppImpl();
		
		app.addListener(c1);
		app.addListener(c2);
	}

	/**
	 * Test method for {@link mockapp.SampleServerAppImpl#method1()}.
	 */
	public void testMethod1() {
		// nothing to do
	}

	/**
	 * Test method for {@link mockapp.SampleServerAppImpl#method2()}.
	 */
	public void testMethod2() {
		assertTrue(app.method2() == 'c');
		try {
			assertTrue(String.valueOf(MethodUtils.invokeExactMethod(app, "method2", null)).equals(String.valueOf('c')));
		} catch (Exception e) {
			fail(e.getMessage());
		}
	}

	/**
	 * Test method for {@link mockapp.SampleServerAppImpl#method3()}.
	 */
	public void testMethod3() {
		assertEquals("string", app.method3());
		try {
			assertEquals("string", String.valueOf(MethodUtils.invokeExactMethod(app, "method3", null)));
		} catch (Exception e) {
			fail(e.getMessage());
		}
	}

	/**
	 * Test method for {@link mockapp.SampleServerAppImpl#method4()}.
	 */
	public void testMethod4() {
		assertTrue(app.method4() == 25);
	}

	/**
	 * Test method for {@link mockapp.SampleServerAppImpl#method5()}.
	 */
	public void testMethod5() {
		assertTrue(app.method5() == 25);
	}

	/**
	 * Test method for {@link mockapp.SampleServerAppImpl#method6()}.
	 */
	public void testMethod6() {
		assertTrue(app.method6() == 25.0f);
	}

	/**
	 * Test method for {@link mockapp.SampleServerAppImpl#method7()}.
	 */
	public void testMethod7() {
		assertTrue(app.method7() == 25.0d);
	}

	/**
	 * Test method for {@link mockapp.SampleServerAppImpl#method8()}.
	 */
	public void testMethod8() {
		assertTrue(app.method8().getClass().equals(Date.class));

		Date date = null;
		try {
			date = (new SimpleDateFormat("dd/MM/yyyy")).parse("01/01/2008");
		} catch (ParseException e) {
			fail(e.getMessage());
		}
		
		assertEquals(date, app.method8());
	}

	/**
	 * Test method for {@link mockapp.SampleServerAppImpl#method10(char, java.lang.String, int, long, float, double)}.
	 */
	public void testMethod10() {
		// nothing to do
	}
	
	
	public void testNotify() {
		assertFalse(c1.isVar());
		assertTrue(c1.getCh() == 0);
		assertNull(c1.getText());
		
		assertFalse(c2.isVar());
		assertTrue(c2.getCh() == 0);
		assertNull(c2.getText());
		
		app.notify1();
		assertTrue(c1.isVar());
		assertTrue(c1.getCh() == 0);
		assertNull(c1.getText());
		
		assertTrue(c2.isVar());
		assertTrue(c2.getCh() == 0);
		assertNull(c2.getText());
		
		app.notify2('z');
		assertTrue(c1.isVar());
		assertTrue(c1.getCh() == 'z');
		assertNull(c1.getText());
		
		assertTrue(c2.isVar());
		assertTrue(c2.getCh() == 'z');
		assertNull(c2.getText());
		
		app.notify3("text");
		assertTrue(c1.isVar());
		assertTrue(c1.getCh() == 'z');
		assertEquals("text", c1.getText());
		
		assertTrue(c2.isVar());
		assertTrue(c2.getCh() == 'z');
		assertEquals("text", c2.getText());
	}

}
